import request from '@/utils/request'
import {ListRequest, RoleRequest, RoleMenusRequest, RoleMenusListRequest, RoleApisListRequest, RoleApisRequest} from '@/interface/role'
import {RoleStatusRequest} from "@/interface/role";

//角色分页
export const RoleListR = (req: ListRequest) => {
  return request({
    method: 'GET',
    url: '/role',
    params: req,
  })
}

//全部角色
export const RolesR = () => {
  return request({
    method: 'GET',
    url: '/role/all',
  })
}

//添加角色
export const RoleAddR = (req: RoleRequest) => {
  return request({
    method: 'POST',
    url: '/role',
    data: JSON.stringify(req),
  })
}

//删除角色
export const RoleRemoveR = (req: RoleMenusListRequest) => {
  return request({
    method: 'DELETE',
    url: `/role`,
    params: req
  })
}

//修改角色
export const RoleUpdateR = (req: RoleRequest) => {
  return request({
    method: 'PUT',
    url: '/role',
    data: JSON.stringify(req),
  })
}

//修改用户状态
export const RoleStatusR = (req: RoleStatusRequest) => {
  return request({
    method: 'PATCH',
    url: '/role/status',
    data: JSON.stringify(req),
  })
}

//角色菜单列表
export const RoleMenuListR = (req: RoleMenusListRequest) => {
  return request({
    method: 'GET',
    url: `/role/menus`,
    // data: JSON.stringify(req),
    params: req
  })
}

//分配角色菜单列表
export const RoleMenuDistributeR = (req: RoleMenusRequest) => {
  return request({
    method: 'PUT',
    url: `/role/menus`,
    data: JSON.stringify(req)
  })
}

//角色的 API 列表
export const RoleApiListR = (req: RoleApisListRequest) => {
  return request({
    method: 'GET',
    url: `/role/apis`,
    params: req
  })
}

//分配角色的 API 列表
export const RoleApiDistributeR = (req: RoleApisRequest) => {
  return request({
    method: 'PUT',
    url: `/role/apis`,
    data: JSON.stringify(req)
  })
}

